package com.linkq.ipinyin.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.linkq.ipinyin.model.Customer;
import com.linkq.ipinyin.model.IOSSubscriptionNotification;
import com.linkq.ipinyin.model.Order;
import com.linkq.ipinyin.model.SubscriptionHistory;
import com.linkq.ipinyin.service.AppleReceiptVerifier;
import com.linkq.ipinyin.service.CustomerService;
import com.linkq.ipinyin.service.OrderService;
import com.linkq.ipinyin.utils.AppleJwtValidator;
import com.linkq.ipinyin.utils.ApplePublicKeyFetcher;
import com.linkq.ipinyin.vo.ResultInfo;
import io.jsonwebtoken.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;

/**
 * @author wangpeng
 * @since 2025-06-29
 **/

@RestController
@RequestMapping("/iap/apple")
@Slf4j
public class AppleNotificationController {
    @Autowired
    private AppleReceiptVerifier appleReceiptVerifier;
    @Autowired
    private OrderService orderService;
    @Autowired
    private CustomerService customerService;

    @PostMapping("/server-notifications")
    public ResponseEntity<String> handleServerNotification(
            @RequestBody Map<String, String> payload
    ) throws Exception {
        log.info("************************** 订阅回调开始 ***************************");
        String signedPayload = payload.get("signedPayload");
        Claims claims = AppleJwtValidator.validateAppleJwt(signedPayload);
        Map<String, Object> data = claims.get("data", Map.class);
        String environment = (String) data.get("environment");
        String signedTransactionInfo = (String) data.get("signedTransactionInfo");
        Claims transactionClaims = AppleJwtValidator.validateAppleJwt(signedTransactionInfo);
        String signedRenewalInfo = data.get("signedRenewalInfo").toString();
        Claims signClaims = AppleJwtValidator.validateAppleJwt(signedRenewalInfo);
        // 原订单号 对应首次支付的订单号
        String originalTransactionId = (String) transactionClaims.get("originalTransactionId");
        String productId = (String) transactionClaims.get("productId");
        String notificationType = (String) claims.get("notificationType");

        switch (notificationType) {
            case "CANCEL":
                // 用户取消订阅
                break;

            case "DID_RENEW":
                // 自动续订成功
                renewal(originalTransactionId, productId);
                break;

            case "INTERACTIVE_RENEWAL":
                // 用户手动续订
                break;

            case "DID_CHANGE_RENEWAL_STATUS":
                // 续订状态变更
                break;

            case "DID_FAIL_TO_RENEW":
                // 续订失败
                break;

            case "EXPIRED":
                // 订阅过期
                break;
        }
        log.info("************************** 订阅回调结束 ***************************");
        return ResponseEntity.ok("OK");
    }

    public Boolean renewal(String originalTransactionId, String productId) {
        SubscriptionHistory subscriptionHistory = new SubscriptionHistory();
        Order order = orderService.selectOne(
                Wrappers.<Order>lambdaQuery()
                        .eq(Order::getOriginalTransactionId, originalTransactionId)
        );
        // 如果原订单号不存在则返回false
        if (order == null) {
            return false;
        }
        int userId = order.getUserId();
        return true;


    }

    @GetMapping("testNotify")
    public ResultInfo testNotify() throws Exception {
        String signedPayload = "eyJhbGciOiJFUzI1NiIsIng1YyI6WyJNSUlFTURDQ0E3YWdBd0lCQWdJUWZUbGZkMGZOdkZXdnpDMVlJQU5zWGpBS0JnZ3Foa2pPUFFRREF6QjFNVVF3UWdZRFZRUURERHRCY0hCc1pTQlhiM0pzWkhkcFpHVWdSR1YyWld4dmNHVnlJRkpsYkdGMGFXOXVjeUJEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURUxNQWtHQTFVRUN3d0NSell4RXpBUkJnTlZCQW9NQ2tGd2NHeGxJRWx1WXk0eEN6QUpCZ05WQkFZVEFsVlRNQjRYRFRJek1Ea3hNakU1TlRFMU0xb1hEVEkxTVRBeE1URTVOVEUxTWxvd2daSXhRREErQmdOVkJBTU1OMUJ5YjJRZ1JVTkRJRTFoWXlCQmNIQWdVM1J2Y21VZ1lXNWtJR2xVZFc1bGN5QlRkRzl5WlNCU1pXTmxhWEIwSUZOcFoyNXBibWN4TERBcUJnTlZCQXNNSTBGd2NHeGxJRmR2Y214a2QybGtaU0JFWlhabGJHOX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JTbUFiUHZTdlU2S1lvZUM3N19UY2JNNFdsaXVVUmVDVFNOYW5wZUs1ZklORGciLCJzdGF0dXMiOjN9LCJ2ZXJzaW9uIjoiMi4wIiwic2lnbmVkRGF0ZSI6MTc1MTI5ODEwNDM2MH0.YQKsSqxG_FHiSimG5Mt8VTtZDLxLMYpyQuc00Qw_va3Xxguu1VwOysj_Ly0ZVvfJZ0MghVIAOsU3SUiW8pC_iA";
        Claims claims = AppleJwtValidator.validateAppleJwt(signedPayload);
        Map<String, Object> data = claims.get("data", Map.class);
        String signedRenewalInfo = data.get("signedRenewalInfo").toString();
        Claims signClaims = AppleJwtValidator.validateAppleJwt(signedRenewalInfo);
        String signedTransactionInfo = data.get("signedTransactionInfo").toString();
        Claims transactionClaims = AppleJwtValidator.validateAppleJwt(signedRenewalInfo);
        return ResultInfo.success();
    }

    @PostMapping("getData")
    public ResultInfo getData(@RequestParam(value = "data") String data) throws Exception {
        Claims claims = AppleJwtValidator.validateAppleJwt(data);
        return ResultInfo.success();
    }

}
